﻿using NConf.ConfigSources;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace NConfTests
{
    
    
    /// <summary>
    ///This is a test class for INIConfigSourceTest and is intended
    ///to contain all INIConfigSourceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class INIConfigSourceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes

        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            // Create ini file.
            var sw = new StreamWriter("test.ini");
            sw.WriteLine("[General]");
            sw.WriteLine("foo=bar");
            sw.WriteLine("other = value");
            sw.WriteLine("something.test = true");
            sw.WriteLine("");
            sw.WriteLine("; Test Comment");
            sw.WriteLine("");
            sw.WriteLine("[Second.Section]");
            sw.WriteLine("test = 21");

            sw.Close();
        } // end MyclassInitialize

        #endregion

        [TestMethod()]
        [DeploymentItem("NConf.dll")]
        public void ConstructorTest()
        {
            var source = new INIConfigSource("test.ini");
            dynamic key = source.GetConfigKey("General");
            Assert.AreEqual("bar", key.foo);
        } // end IniConfigSourceConstructorTest()

        [TestMethod()]
        [DeploymentItem("NConf.dll")]
        public void KeysWithSpacesTest()
        {
            var source = new INIConfigSource("test.ini");
            dynamic key = source.GetConfigKey("General");
            Assert.AreEqual("value", key.other);
        } // end IniConfigSourceConstructorTest()
        
        [TestMethod()]
        [DeploymentItem("NConf.dll")]
        public void KeysWithPeriodsTest()
        {
            var source = new INIConfigSource("test.ini");
            dynamic key = source.GetConfigKey("General");
            Assert.AreEqual("true", key.something.test);
        } // end IniConfigSourceConstructorTest()
        
        [TestMethod()]
        [DeploymentItem("NConf.dll")]
        public void SectionWithPeriodTest()
        {
            var source = new INIConfigSource("test.ini");
            dynamic key = source.GetConfigKey("Second.Section");
            Assert.AreEqual("21", key.test);
        } // end IniConfigSourceConstructorTest()
    }
}
